<?php
/**
 * 下载页
 */

$dblink = new DataBase();

if (isset($_GET['bookid'])) {
    
    //查询书籍信息
    $query = "select * from books where id = {$_GET['bookid']}";
    $result = $dblink->query($query)->fetch();
    $dir_name = date('Ymd', strtotime($result['created_at']));
    
    //更新日,周,月下载次数
    $query = "update books set down = " . strval($result['down'] + 1)." ,
                               month_down = " . strval($result['month_down'] + 1)." ,
                               day_down = " . strval($result['day_down'] + 1).",
                               week_down = " . strval($result['week_down'] + 1). "
                               where id = {$_GET['bookid']}";
    $dblink->query($query);
    
    //输出文件
    echo file_get_contents(ROOT.'/books/'.$dir_name.'/'.$result['file']);
}
